package cn.cheegon.blog.controller;

import cn.cheegon.blog.common.api.CommonPage;
import cn.cheegon.blog.common.api.CommonResult;
import cn.cheegon.blog.entity.dto.CmsBlogDto;
import cn.cheegon.blog.entity.dto.CommentDto;
import cn.cheegon.blog.model.CmsComment;
import cn.cheegon.blog.service.CmsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author cheegon
 * @since 2024-06-21
 */
@RestController
@RequestMapping("/admin/comment/*")
public class AdminCommentController extends AdminController {
    @Autowired
    private CmsCommentService cmsCommentService;

    @GetMapping("list")
    public CommonResult<CommonPage<CommentDto>> getCommentList(@RequestParam(name = "blogId", required = false) Long blogId,
                                                               @RequestParam(name = "status", required = false) Integer status,
                                                               @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return CommonResult.success(cmsCommentService.getList(blogId, status, pageNum, pageSize));
    }

    @GetMapping("updateStatus")
    public CommonResult updateCommentStatus(@RequestParam(name = "id") Long id,
                                            @RequestParam(name = "status") Integer status) {
        CmsComment dto = new CmsComment();
        dto.setId(id);
        dto.setStatus(status);
        cmsCommentService.edit(dto);
        return CommonResult.success();
    }

    @GetMapping("del/{id}")
    public CommonResult del(@PathVariable Long id) {
        checkAdmin();
        cmsCommentService.del(id);
        return CommonResult.success();
    }
}
